package com.bee.剑指offer;

import java.util.ArrayDeque;
import java.util.Queue;

public class 调整数组顺序使奇数位于偶数前面2 {

    public int[] reOrderArrayTwo(int[] array) {
        if (array.length == 0) {
            return array;
        }
        Queue<Integer> osu = new ArrayDeque<>();
        Queue<Integer> jsu = new ArrayDeque<>();

        for (int i = 0; i < array.length; i++) {
            if (array[i] % 2 == 0) {
                osu.offer(array[i]);
            } else {
                jsu.offer(array[i]);
            }
        }
        for (int i = 0; i < array.length; i++) {
            if (!jsu.isEmpty()) {
                array[i] = jsu.poll();
            } else {
                array[i] = osu.poll();
            }
        }
        return array;
    }

    public static void main(String[] args) {

    }
}
